package logic.SysOrganization

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import cn.ibizlab.core.ad.domain.SysOrganization
import cn.ibizlab.core.ad.service.SysOrganizationService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  获取单位标识
 */
class FindOrganizationId {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    def _checkkey = new EntityBase()
    def _filter = new EntityBase()
    //item
    def _item = new SysOrganization()
    //list
    def _list = new SysOrganization()
    def _ret = new EntityBase()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //id不为空
        if(((RuleUtils.test(_default.get('id'), 'ISNOTNULL', 'null')))) {
            deaction1()
        }
        //编号不为空
        else if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')) && (RuleUtils.test(_default.get('organization_number'), 'ISNOTNULL', 'null')))) {
            prepareparam4()
        }
        //名称不为空
        else if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')) && (RuleUtils.test(_default.get('organization_name'), 'ISNOTNULL', 'null')))) {
            prepareparam3()
        }
    }

    //准备参数
    def prepareparam3() {
        _default.set("n_organization_name_eq", _default.get("organization_name"))
        _filter.set("n_dc_eq", _default.get("dc"))

        if(true) {
            dedataquery1()
        }
    }

    //准备参数
    def prepareparam4() {
        _filter.set("n_organization_number_eq", _default.get("organization_number"))
        _filter.set("n_dc_eq", _default.get("dc"))

        if(true) {
            dedataquery1()
        }
    }

    //校验id是否存在
    def deaction1() {
        SpringContextHolder.getBean(SysOrganizationService.class).checkKey(_default)

        //已存在
        if(((RuleUtils.test(_checkkey, 'EQ', '1')))) {
            prepareparam1()
        }
        //不存在
        if(((RuleUtils.test(_checkkey, 'NOTEQ', '1')))) {
            prepareparam2()
        }
    }

    //准备参数
    def prepareparam2() {
        _filter.set("n_organization_number_eq", _default.get("id"))
        _filter.set("n_dc_eq", _default.get("dc"))

        if(true) {
            dedataquery1()
        }
    }

    //查询单位
    def dedataquery1() {
        //DEDataQuery 暂未实现
        //循环
        if(true) {
            loopsubcall1()
        }
        //连接名称
        if(true) {
            end1()
        }
    }

    //循环子调用
    def loopsubcall1() {
    //未支持的处理节点

        if(true) {
            prepareparam5()
        }
    }

    //设置返回值
    def prepareparam1() {
        _ret.set("", _default.get("id"))

        if(true) {
            end1()
        }
    }

    //设置返回id
    def prepareparam5() {
        _ret.set("", _item.get("id"))

    }

    //结束
    def end1() {
        _return = _ret

    }

}
